/* eslint-disable */
import Vue from 'vue';
import Router from 'vue-router';
import Layout from '../views/layout/Layout';
import eosRouter from './eosRouter';
import tronRouter from './tronRouter';
import appName from '@/utils/environments';

Vue.use(Router);

/**
 * @for meta
 * @param title 标题
 * @param icon 图标
 * @param name 用来匹配路由名称
 */

const constantRouter = [
  // 首页
  {
    path: '/',
    redirect: '/',
    component: Layout,
    meta: { title: 'index' },
    children: [
      {
        path: '/',
        name: 'index',
        component: resolve => require(['@/views/index/Index'], resolve),
        meta: { title: 'index' },
      },
    ]
  },
  // 币币交易中心
  {
    path: '/trade/:trade',
    component: Layout,
    redirect: '/trade/:trade',
    meta: { title: 'Exchange' },
    children: [
      {
        path: '/trade/:trade',
        name: 'trade',
        component: resolve => require(['@/views/tradingCenter/Index'], resolve),
        meta: { title: 'Exchange', tradeMenu: true, resource: true },
      }
    ],
  },
  // otc
  {
    path: '/otc',
    component: Layout,
    meta: { title: 'otc' },
    children: [
      {
        path: '/otc',
        name: 'otc',
        component: resolve => require(['@/views/otc/Index'], resolve),
        meta: { title: 'otc' },
      },
    ]
  },
  // 稳定币
  {
    path: '/danchor',
    component: Layout,
    meta: { title: 'stableCoin' },
    children: [
      {
        path: '/danchor',
        name: 'stableCoin',
        component: resolve => require(['@/views/stablecoin/Index'], resolve),
        meta: { title: 'stableCoin' },
      },
    ]
  },
  // 订单中心
  {
    path: '/my-order',
    component: Layout,
    meta: { title: 'myorder' },
    children: [
      {
        path: '/',
        name: 'myOrder',
        component: resolve => require(['@/views/order/Index.vue'], resolve),
        meta: { title: 'myorder', isUser: true  },
      },
    ]
  },
  // 行情
  {
    path: '/market',
    component: Layout,
    redirect: '/market',
    meta: { title: 'market' },
    children: [
      {
        path: '',
        name: 'market',
        component: resolve => require(['@/views/market/Index'], resolve),
        meta: { title: 'market' },
      }
    ],
  },
  // 上币申请
  {
    path: '/apply', // 上币申请
    component: Layout,
    redirect: '/apply',
    meta: { title: 'applyCode' },
    children: [
      {
        path: '',
        name: 'applyCode',
        component: resolve => require(['@/views/apply/Index'], resolve),
        meta: { title: 'applyCode' },
      }
    ],
  },
  // cmc 币种状态
  {
    path: '/page/status',
    component: Layout,
    redirect: '/page/status',
    meta: { title: 'cmcStatus' },
    children: [
      {
        path: '',
        name: 'cmcStatus',
        component: resolve => require(['@/views/cmc/Index'], resolve),
        meta: { title: 'cmcStatus' },
      }
    ],
  },
  // 错误码处理
  {
    path: '/error',
    component: resolve => require(['@/views/error-page/Error.vue'], resolve),
    meta: { title: 'Newdex - Error Code' },
  },
  // 404
  {
    path: '*',
    name: 'nopage',
    component: resolve => require(['@/views/error-page/404.vue'], resolve),
    meta: { title: '404 - Newdex' },
  },
];

if (appName === 'tronNewdex') {
  constantRouter.push(...tronRouter);
} else {
  constantRouter.push(...eosRouter);
}

export default new Router({
  base: '/',
  mode: 'history',
  routes: constantRouter,
});
